package com.foreknow.service;

import com.foreknow.entity.User;
import com.foreknow.dao.impl.UserDaoImpl;

import java.sql.SQLException;
import java.util.List;

public class UserService {

    public boolean insert(User user){
        boolean  isOK =false;
        UserDaoImpl dao  = new UserDaoImpl();
        String sql = "insert into user(username,password,account,phone,email,avater) values(?,?,?,?,?,?)";
        Object params[]={user.getUsername(),user.getPassword(),user.getAccount(),user.getPhone(),user.getEmail(),user.getAvater()};
        try {
            int isRight=  dao.insert(sql,params);
            if(isRight>0){
                isOK =true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return isOK;
    }

    public User denglu(String username,String password){
        UserDaoImpl dao = new UserDaoImpl();
        String sql = "select * from user where username=? and password=?";
        User user = new User();


        try {
           user=dao.queryOne(sql,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return  user;
    }
    public User Login(String username,String password){
        UserDaoImpl dao = new UserDaoImpl();
        String sql = "select * from user where username=? and password=?";
        User user = new User();


        try {
            user=(User) dao.queryByCondition(sql,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

            return user;
    }
}













